home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / bash_completion.d / xm < prev    next >
Encoding:
Text File  |  2010-11-16  |  7.4 KB  |  233 lines

  1. # bash completion for xm
  2.  
  3. have xm && {
  4. _xen_domain_names()
  5. {
  6.     COMPREPLY=( $(compgen -W "$( xm list 2>/dev/null | \
  7.         awk '!/Name|Domain-0/ { print $1 }'  )" -- "$cur") )
  8. }
  9.  
  10. _xen_domain_ids()
  11. {
  12.     COMPREPLY=( $(compgen -W "$( xm list 2>/dev/null | \
  13.         awk '!/Name|Domain-0/ { print $2 }' )" -- "$cur") )
  14. }
  15.  
  16. _xm()
  17. {
  18.     # TODO: _split_longopt
  19.  
  20.     local cur prev command options
  21.  
  22.     COMPREPLY=()
  23.     _get_comp_words_by_ref cur prev
  24.  
  25.     commands='console create new delete destroy domid domname dump-core \
  26.         list mem-max mem-set migrate pause reboot rename restore \
  27.         resume save shutdown start suspend sysrq trigger top unpause \
  28.         uptime vcpu-list vcpu-pin vcpu-set debug-keys dmesg info log \
  29.         serve sched-credit sched-sedf block-attach block-detach \
  30.         block-list network-attach network-detach network-list \
  31.         vtpm-list vnet-list vnet-create vnet-delete labels addlabel \
  32.         rmlabel getlabel dry-run resources makepolicy loadpolicy \
  33.         cfgbootpolicy dumppolicy help'
  34.  
  35.     if [[ $COMP_CWORD -eq 1 ]] ; then
  36.         COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
  37.     else
  38.         if [[ "$cur" == *=* ]]; then
  39.             prev=${cur/=*/}
  40.             cur=${cur/*=/}
  41.         fi
  42.  
  43.         command=${COMP_WORDS[1]}
  44.         if [[ "$cur" == -* ]]; then
  45.             # possible options for the command
  46.             case $command in
  47.                 create)
  48.                     options='-c'
  49.                     ;;
  50.                 dmesg)
  51.                     options='--clear'
  52.                     ;;
  53.                 list)
  54.                     options='--long'
  55.                     ;;
  56.                 reboot)
  57.                     options='-w -a'
  58.                     ;;
  59.                 shutdown)
  60.                     options='-w -a -R -H'
  61.                     ;;
  62.                 sched-credit)
  63.                     options='-d -w -c'
  64.                     ;;
  65.                 block-list|network-list|vtpm-list|vnet-list)
  66.                     options='-l --long'
  67.                     ;;
  68.                 getpolicy)
  69.                     options='--dumpxml'
  70.                     ;;
  71.                 new)
  72.                     options='-h --help --help_config -q \
  73.                         --quiet --path= -f= \
  74.                         --defconfig= -F= --config= \
  75.                         -b --dryrun -x --xmldryrun \
  76.                         -s --skipdtd -p --paused -c \
  77.                         --console_autoconnect'
  78.                     ;;
  79.             esac
  80.             COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
  81.         else
  82.             case $command in
  83.                 console|destroy|domname|domid|list|mem-set|mem-max| \
  84.                 pause|reboot|rename|shutdown|unpause|vcpu-list|vcpu-pin| \
  85.                 vcpu-set|block-list|network-list|vtpm-list)
  86.                     _count_args
  87.                     case $args in
  88.                         2)
  89.                             _xen_domain_names
  90.                             ;;
  91.                     esac
  92.                     ;;
  93.                 migrate)
  94.                     _count_args
  95.                         case $args in
  96.                         2)
  97.                             _xen_domain_names
  98.                             ;;
  99.                         3)
  100.                             _known_hosts_real "$cur"
  101.                             ;;
  102.                     esac
  103.                     ;;
  104.                 restore|dry-run|vnet-create)
  105.                     _filedir
  106.                     ;;
  107.                 save)
  108.                     _count_args
  109.                     case $args in
  110.                         2)
  111.                             _xen_domain_names
  112.                             ;;
  113.                         3)
  114.                             _filedir
  115.                             ;;
  116.                     esac
  117.                     ;;
  118.                 sysrq)
  119.                     _count_args
  120.                     case $args in
  121.                         2)
  122.                             _xen_domain_names
  123.                             ;;
  124.                         3)
  125.                             COMPREPLY=( $(compgen -W "r s e i u b" -- "$cur") )
  126.                             ;;
  127.                     esac
  128.                     ;;
  129.                 block-attach)
  130.                     _count_args
  131.                     case $args in
  132.                         2)
  133.                             _xen_domain_names
  134.                             ;;
  135.                         3)
  136.                             COMPREPLY=( $(compgen -W "phy: file:" -- "$cur") )
  137.                             ;;
  138.                         5)
  139.                             COMPREPLY=( $(compgen -W "w r" -- "$cur") )
  140.                             ;;
  141.                         6)
  142.                             _xen_domain_names
  143.                             ;;
  144.                     esac
  145.                     ;;
  146.                 block-detach)
  147.                     _count_args
  148.                     case $args in
  149.                         2)
  150.                             _xen_domain_names
  151.                             ;;
  152.                         3)
  153.                             COMPREPLY=( $(compgen -W "$( xm block-list $prev \
  154.                                 2>/dev/null | awk '!/Vdev/ { print $1 }' )" \
  155.                                 -- "$cur") )
  156.                             ;;
  157.                     esac
  158.                     ;;
  159.                 network-attach)
  160.                     _count_args
  161.                     case $args in
  162.                         2)
  163.                             _xen_domain_names
  164.                             ;;
  165.                         *)
  166.                             COMPREPLY=( $(compgen -W "script= ip= mac= \
  167.                                 bridge= backend=" -- "$cur") )
  168.                             ;;
  169.                     esac
  170.                     ;;
  171.                 network-detach)
  172.                     _count_args
  173.                     case $args in
  174.                         2)
  175.                             _xen_domain_names
  176.                             ;;
  177.                         3)
  178.                             COMPREPLY=( $(compgen -W "$( xm network-list $prev \
  179.                                 2>/dev/null | awk '!/Idx/ { print $1 }' )" \
  180.                                 -- "$cur") )
  181.                             ;;
  182.                     esac
  183.                     ;;
  184.                 sched-credit)
  185.                     case $prev in
  186.                         -d)
  187.                             _xen_domain_names
  188.                             return 0
  189.                             ;;
  190.                     esac
  191.                     ;;
  192.                 create)
  193.                     _filedir
  194.                     COMPREPLY=( ${COMPREPLY[@]:-} \
  195.                         $( compgen -W '$( command ls /etc/xen 2>/dev/null )' \
  196.                         -- "$cur" ) )
  197.                     ;;
  198.                 new)
  199.                     case $prev in
  200.                         -f|-F|--defconfig|--config)
  201.                             _filedir
  202.                             return 0
  203.                             ;;
  204.                         --path)
  205.                             _filedir -d
  206.                             return 0
  207.                             ;;
  208.                     esac
  209.  
  210.                     _count_args
  211.                         case $args in
  212.                         2)
  213.                             _xen_domain_names
  214.                             ;;
  215.                     esac
  216.                     ;;
  217.             esac
  218.         fi
  219.     fi
  220.  
  221.     return 0
  222. }
  223. complete -F _xm xm
  224. }
  225.  
  226. # Local variables:
  227. # mode: shell-script
  228. # sh-basic-offset: 4
  229. # sh-indent-comment: t
  230. # indent-tabs-mode: nil
  231. # End:
  232. # ex: ts=4 sw=4 et filetype=sh
  233.